Blog testing ad fixes

jamesperet 9 jaren geleden
bovenliggende
commit
458360184c

+ 1 - 1
app/views/admin_panel/posts.html.erb

@@ -23,7 +23,7 @@
23 23
 			 <div class="btn-group btn-group-vertical">
24 24
 		      	<%= link_to '<i class="icon-eye-open"></i>'.html_safe, post_path(post), :class => 'btn' %>
25 25
 		      	<%= link_to '<i class="icon-pencil"></i>'.html_safe, edit_blog_post_path(post), :class => 'btn' %>
26
-		      	<%= link_to '<i class="icon-remove"></i>'.html_safe, post, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-danger' %>
26
+		      	<%= link_to '<i class="icon-remove"></i>'.html_safe, post, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-danger', :id => ['delete_' + post.slug] %>
27 27
 			 </div>
28 28
 		  </div>
29 29
 		</div>

+ 1 - 1
app/views/blog_posts/show.html.erb

@@ -7,6 +7,6 @@
7 7
 
8 8
 
9 9
 <div style="margin-top: 40px; text-align: center;">
10
-<%= link_to (t "nav.edit"), edit_blog_post_path(@blog_post), :class => 'btn btn-small' if user_signed_in? %>	
10
+<%= link_to (t "nav.edit"), edit_blog_post_path(@blog_post), :class => 'btn btn-small', :id => ['edit_' + @blog_post.slug] if user_signed_in? %>	
11 11
 <%= link_to (t "nav.back"), blog_path, :class => 'btn btn-small' %>
12 12
 </div>

+ 1 - 1
app/views/layouts/_navigation_links.html.erb

@@ -12,7 +12,7 @@
12 12
 			</a>
13 13
 		    	<ul class="dropdown-menu">
14 14
 				<% if current_user.admin %>
15
-					<li><%= link_to (t "nav.admin_panel"), admin_dashboard_path %></li>
15
+					<li><%= link_to (t "nav.admin_panel"), admin_dashboard_path, :id => 'navlink_admin_panel' %></li>
16 16
 				<% end %>
17 17
 	  			<li><%= link_to (t "nav.account"), edit_user_registration_path %></li>
18 18
 	  			<li><%= link_to (t "nav.logout"), destroy_user_session_path, method: :delete %></li>

+ 1 - 1
config/locales/en.yml

@@ -246,7 +246,7 @@ en:
246 246
     login: Login
247 247
     signup: Sign Up
248 248
     back: Back
249
-    edit: Editar
249
+    edit: Edit
250 250
   blog:
251 251
     by: By
252 252
     ago: ago

+ 1 - 1
config/routes.rb

@@ -21,7 +21,7 @@ RailsWebsiteTemplate::Application.routes.draw do
21 21
   
22 22
   post "upload" => "uploads#upload", :as => :post_upload
23 23
   get "blog" => "blog_posts#index", :as => :blog
24
-  get "post/:id" => "blog_posts#show", :as => :post
24
+  get "blog/:id" => "blog_posts#show", :as => :post
25 25
   resources :blog_posts, path: '/admin/posts'
26 26
   
27 27
   get '/admin/files' => "admin_panel#files", :as => :admin_files

+ 38 - 5
features/blog.feature

@@ -10,28 +10,61 @@ Feature: Manage Articles
10 10
 	| Test 001    | 1 2 3 testing          | true      | Testing the website | test_001    |
11 11
 
12 12
 	@focus	
13
-	Scenario: Blog Posts List 
13
+	Scenario: Blog posts list 
14 14
 		When I go to the blog page 
15 15
 		Then I should see "Hello World" 
16 16
 		And I should see "First Post"
17 17
 		And I should see "Test 001" 
18 18
 		And I should see "Testing the website"
19 19
 	
20
-	Scenario: Posts Page 
20
+	Scenario: Blog post page 
21 21
 		When I go to the blog page 
22 22
 		And I click in the link "Hello World" 
23 23
 		Then I should see "Hello World" 
24 24
 		And I should see "Welcome to the website"
25
+		And The current url should be "/blog/hello_world"
25 26
 
26
-	Scenario: Post Article
27
+	Scenario: New blog post
27 28
 		Given I am logged in as admin
28 29
 		Then I click in the link "Admin Panel"
29 30
 		And I click in the link "Posts"
30
-		And I click in the link "New Post"
31
+		And The current url should be "/admin/posts"
32
+		Then I click in the link "New Post"
33
+		And The current url should be "/admin/posts/new"
31 34
 		Then I fill in "Title" with "Test 002"
32 35
 		And I fill in "Slug" with "test_002"
33 36
 		And I fill in "Description" with "Another blog post test"
34 37
 		And I fill in "post_content" with "This is blog post test number 002!"
35 38
 		And I click in the button "Save"
36 39
 		Then I should see "Test 002"
37
-		And I should see "This is blog post test number 002!"
40
+		And I should see "This is blog post test number 002!"
41
+		And I should see "Admin"
42
+		
43
+	Scenario: Delete blog post
44
+		Given I am logged in as admin
45
+		Then I click in the link "Admin Panel"
46
+		Then I click in the link "Posts"
47
+		And The current url should be "/admin/posts"
48
+		Then I should see "Hello World"
49
+		And I should see "Test 001"
50
+		Then I click in the link "delete_hello_world"
51
+		Then I should see "Test 001"
52
+		And I should not see "Hello World"
53
+		
54
+	Scenario: Only admin users can see edit blog post button
55
+		Given I go to the blog page 
56
+		And I click in the link "Hello World"
57
+		Then I should not see the link "edit_hello_world"
58
+		Then I log in as admin
59
+		And I go to the blog page 
60
+		And I click in the link "Hello World"
61
+		Then I should see the link "edit_hello_world"
62
+		
63
+	Scenario: Only admin users can access the blog posts admin page
64
+		Given I go to the blog page 
65
+		Then I should not see the link "navlink_admin_panel"
66
+		Then I go to the admin blog posts page
67
+		And I should see "You dont have permission to access that page!"
68
+		Then I log in as admin
69
+		And I go to the admin blog posts page
70
+		Then The current url should be "/admin/posts"

+ 29 - 4
features/step_definitions/blog_steps.rb

@@ -21,10 +21,27 @@ When /^I go to (.+)$/ do |page_name|
21 21
   path_to(page_name)
22 22
 end
23 23
 
24
+Then(/^The current url should be "(.*?)"$/) do |arg1|
25
+  uri = URI.parse(current_url)
26
+  "#{uri.path}".should == arg1
27
+end
28
+
24 29
 Then(/^I should see "(.*?)"$/) do |arg1|
25 30
   page.should have_content(arg1)
26 31
 end
27 32
 
33
+Then(/^I should not see "(.*?)"$/) do |arg1|
34
+  page.should have_no_content(arg1)
35
+end
36
+
37
+Then(/^I should see the link "(.*?)"$/) do |arg1|
38
+  find_link(arg1).visible?
39
+end
40
+
41
+Then(/^I should not see the link "(.*?)"$/) do |arg1|
42
+  assert has_no_link?(arg1)
43
+end
44
+
28 45
 Then(/^I should see "(.*?)" And I should see "(.*?)"$/) do |arg1, arg2|
29 46
   page.should have_content(arg1)
30 47
   page.should have_content(arg2)
@@ -39,6 +56,18 @@ When(/^I click in the button "(.*?)"$/) do |arg1|
39 56
 end
40 57
 
41 58
 Given(/^I am logged in as admin$/) do
59
+  admin_login
60
+end
61
+
62
+Then(/^I log in as admin$/) do
63
+  admin_login
64
+end
65
+
66
+Then(/^I fill in "(.*?)" with "(.*?)"$/) do |arg1, arg2|
67
+  fill_in arg1, :with => arg2
68
+end
69
+
70
+def admin_login
42 71
   user = FactoryGirl.create(:admin)  
43 72
   visit new_user_session_path  
44 73
   fill_in "Email", :with => 'admin@website.com' 
@@ -46,8 +75,4 @@ Given(/^I am logged in as admin$/) do
46 75
   click_button "Submit"
47 76
   login_as user, scope: :user
48 77
   visit root_path
49
-end
50
-
51
-Then(/^I fill in "(.*?)" with "(.*?)"$/) do |arg1, arg2|
52
-  fill_in arg1, :with => arg2
53 78
 end

+ 3 - 0
features/support/paths.rb

@@ -10,6 +10,9 @@ module NavigationHelpers
10 10
     when/the blog page/ 
11 11
       visit blog_path 
12 12
       
13
+    when/the admin blog posts page/
14
+      visit admin_posts_path
15
+      
13 16
     else
14 17
       raise "Can't find mapping from \"#{page_name}\" to a path."
15 18
     end